# 部署Harbor仓库
# 安装docker-compose
function docker_compose_install()
{
        echo "检查Docker Compose......"
        docker-compose --version
    if [ $? -eq  0 ]; then
        echo "检查到Docker Compose已安装!"
    else
        echo "安装docker compose环境..."
        curl -L "https://github.com/docker/compose/releases/download/1.23.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/sbin/docker-compose
        chmod +x /usr/local/sbin/docker-compose
        echo "安装docker环境...安装完成!"
    fi
}
#安装docker
docker_compose_install

# 下载harbor企业级Registry仓库
cd ~
if [ ! -f "./harbor-offline-installer-v2.0.0.tgz" ];then
  echo "download harbor file"
  wget https://github.com/goharbor/harbor/releases/download/v2.0.0/harbor-offline-installer-v2.0.0.tgz
fi

if [ ! -d "./harbor" ];then
 tar zxvf harbor-offline-installer-v2.0.0.tgz
fi

cd harbor
if [ ! -f "./harbor.yml" ];then
  cp ./harbor.yml.tmpl ./harbor.yml
  # 修改配置文件的hostname与password
  sed -i "s/hostname.*/hostname: 10.100.79.222/g" harbor.yml
  sed -i "s/harbor_admin_password.*/harbor_admin_password: admin/g" harbor.yml
  #如果本地使用，记得注释掉https部分，不然安装会报错
fi

# 将当前仓库添加到docker的配置文件中去，如果原来没有配过daemon，自己手动去配下
if  grep "insecure-registries" /etc/docker/daemon.json
then
    echo "replace insecure-registries"
    sed -i s/\"insecure-registries\".*/\"insecure-registries\":[\"10.100.79.222\"]/g /etc/docker/daemon.json
    systemctl daemon-reload
    systemctl restart docker
fi


docker info

# 开启harbor
./install.sh

# 查看启动情况
docker-compose ps